.PHONY: build clean help dev test

VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
BRANCH := $(shell git symbolic-ref --short HEAD 2>/dev/null)
BUILDDATE := $(shell date "+%Y-%m-%d") 

ifeq ($(OS),Windows_NT)
    PLATFORM := windows
    ARCH := amd64
else
    UNAME_S := $(uname -s)
	
    ifeq ($(UNAME_S),Linux)
        PLATFORM := linux
	else
		PLATFORM := darwin
    endif
	UNAME_M := $(uname -m)
	ifeq ($(UNAME_M),arm64)
        ARCH := arm64
    else
        ARCH := amd64
    endif
endif


help:
	@echo "Usage: make [target]"
	@echo ""
	@echo "Targets:"
	@echo "  help       Show this help message"
	@echo "  dev        Setup development environment"
	@echo "  test       Run tests"
	@echo "  build      Build all components"
	@echo "  clean      Clean release directory"

check_deps:
	@echo "Checking required dependencies..."
	@command -v go >/dev/null 2>&1 || { echo "go is required but not installed. Visit https://golang.org/doc/install" >&2; exit 1; }
	@command -v wails >/dev/null 2>&1 || { echo "wails is required but not installed. Run: go install github.com/wailsapp/wails/v2/cmd/wails@latest" >&2; exit 1; }
	@command -v node >/dev/null 2>&1 || { echo "nodejs is required but not installed. Visit https://nodejs.org/" >&2; exit 1; }

dev: check_deps
	wails dev -ldflags "-X 'main.Version=$(VERSION)'"
build: check_deps
	wails build -clean -ldflags "-X 'main.Version=$(VERSION)'" -platform $(PLATFORM)/$(ARCH)

clean:
	@rm -rf build/bin/*